<?php
/**
 * Created by PhpStorm.
 * User: Edik
 * Date: 2016/3/3
 * Time: 13:48
 */

namespace Admin\Model;


use Think\Model;

class NewsModel extends Model
{
    protected $insertFields = array('title','article_type','content','article_class');
    protected $updateFields = array('id','title','article_type','content');

    protected $_validate = array(
        array('title', 'require', '新闻名称不能为空！', 1, 'regex', 3),
        array('title', '1,50', '新闻名称的值最长不能超过 50 个字符！', 1, 'length', 3),
        array('content', 'require', '新闻内容不能为空！', 1, 'regex', 3),

    );

    // 添加前
    protected function _before_insert(&$data, $option)
    {
        $data['user_id'] = session('a_id');
        $data['create_time'] = time();
    }

    // 修改前
    protected function _before_update(&$data, $option)
    {
        $data['edit_id'] = session('a_id');
        $data['edit_time'] = time();
    }
}